package com.example.stream;

import org.apache.spark.SparkConf;
import org.apache.spark.streaming.Durations;
import org.apache.spark.streaming.api.java.JavaDStream;
import org.apache.spark.streaming.api.java.JavaStreamingContext;

public class SparkStreamingDemo {

    public static void main(String[] args) {
        SparkStreamingDemo demo = new SparkStreamingDemo();
        demo.run();
    }

    public void run(){
        SparkConf sparkConf = new SparkConf().setMaster("local").setAppName("spark-streaming-read-file");
        JavaStreamingContext jsc = new JavaStreamingContext(sparkConf, Durations.seconds(2));
        JavaDStream<String> dStream = jsc.socketTextStream("127.0.0.1", 55533);
        dStream.print();

        try {
            jsc.start();
            jsc.awaitTermination();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
